package com.bw.zg3park2212.fg

import android.annotation.SuppressLint
import android.app.ActionBar.LayoutParams
import android.content.Context
import android.os.Bundle
import android.view.Gravity
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Button
import android.widget.EditText
import android.widget.ImageView
import android.widget.PopupWindow
import androidx.recyclerview.widget.LinearLayoutManager
import com.alibaba.android.arouter.launcher.ARouter
import com.blankj.utilcode.util.ToastUtils
import com.bumptech.glide.Glide
import com.bw.base.entity.GgcommentEntity
import com.bw.base.entity.GgcommentEntityItem
import com.bw.base.entity.SendgonggParam
import com.bw.base.mvvm.BaseFram
import com.bw.zg3park2212.R
import com.bw.zg3park2212.adpter.GonggAdpter
import com.bw.zg3park2212.databinding.FragmentBlank1Binding
import com.bw.zg3park2212.viewmodel.HomeViewModel
import com.youth.banner.BannerConfig
import com.youth.banner.loader.ImageLoader
import dagger.hilt.android.AndroidEntryPoint
import java.text.SimpleDateFormat

@AndroidEntryPoint
class BlankFragment1 : BaseFram<FragmentBlank1Binding,HomeViewModel>() {
    lateinit var gonggAdpter: GonggAdpter
    var image= mutableListOf<Int>(R.drawable.pmou1,R.drawable.pmou1,R.drawable.pmou1)
    @SuppressLint("MissingInflatedId")
    override fun intitView() {
        viewmodel.getGg(8,10)
        gonggAdpter= GonggAdpter()
        binding.rv.layoutManager=LinearLayoutManager(context)
        binding.rv.adapter=gonggAdpter
        binding.tvSendgg.setOnClickListener {
            val inflate = LayoutInflater.from(context).inflate(R.layout.item_popsendgg, null)
            val popupWindow=PopupWindow(context)
            popupWindow.contentView=inflate
            val btnYes = inflate.findViewById<Button>(R.id.btn_yes)
            val btnNo = inflate.findViewById<Button>(R.id.btn_no)
            val guto_whgl = inflate.findViewById<Button>(R.id.guto_whgl)
            val sendtitle = inflate.findViewById<EditText>(R.id.sendgg_title)
            val sendcontent = inflate.findViewById<EditText>(R.id.sendgg_content)
            btnYes.setOnClickListener {
                var sendgonggParam=SendgonggParam()
                sendgonggParam.content=sendcontent.text.toString()
                sendgonggParam.title=sendtitle.text.toString()
                sendgonggParam.publishTime=SimpleDateFormat("yyyy-MM-dd").format(System.currentTimeMillis())
               // viewmodel.sendGg(sendgonggParam)
                viewmodel.sendGg(sendcontent.text.toString(),SimpleDateFormat("yyyy-MM-dd").format(System.currentTimeMillis()),sendtitle.text.toString())
//                gonggAdpter.data.add(GgcommentEntityItem(sendcontent.text.toString(),0,SimpleDateFormat("yyyy-MM-dd").format(System.currentTimeMillis()),"",sendtitle.text.toString(),"",0))
//                gonggAdpter.notifyDataSetChanged()
                popupWindow.dismiss()
            }
            btnNo.setOnClickListener {
                popupWindow.dismiss()
            }
            guto_whgl.setOnClickListener {
                ARouter.getInstance().build("/app/CultureActivity").navigation()
            }
            popupWindow.width=LayoutParams.MATCH_PARENT
            popupWindow.height=600
            popupWindow.isOutsideTouchable=true
            popupWindow.isFocusable=true
            popupWindow.showAtLocation(binding.tvSendgg,Gravity.BOTTOM,0,0)
        }
        binding.banner.setImages(image)
            .setImageLoader(object :ImageLoader(){
                override fun displayImage(context: Context?, path: Any?, imageView: ImageView?) {
                    if (context!=null){
                        if (imageView!=null){
                            Glide.with(context).load(path).into(imageView)
                        }
                    }
                }
            }).setBannerStyle(BannerConfig.NUM_INDICATOR)
            .setDelayTime(2000)
            .start()
        binding.cwgl.setOnClickListener {
            ARouter.getInstance().build("/app/ParkActivity").navigation()
        }
        binding.wxgl.setOnClickListener {
            ARouter.getInstance().build("/app/RepairActivity").navigation()
        }
        binding.fkgl.setOnClickListener {
            ARouter.getInstance().build("/app/FangActivity").navigation()
        }
        binding.kqgl.setOnClickListener {
            ARouter.getInstance().build("/app/SiginlistActivity").navigation()
        }
        binding.sjtj.setOnClickListener {
            ARouter.getInstance().build("/app/StaffActivity").navigation()
        }
        binding.rygl.setOnClickListener {
            ARouter.getInstance().build("/app/EmpActivity").navigation()
        }
        binding.fyxx.setOnClickListener {
            ARouter.getInstance().build("/app/HouseActivity").navigation()
        }
        binding.xjdw.setOnClickListener {
            ARouter.getInstance().build("/app/PointActivity").navigation()
        }
    }

    override fun intitData() {
        viewmodel.ggSuccse.observe(this){
            gonggAdpter.data.clear()
            gonggAdpter.addData(it)
            //gonggAdpter.data.add(GgcommentEntity(it.content,it.id,it.publishTime,it.status,it.title,it.type,it.userId))
            gonggAdpter.notifyDataSetChanged()
        }
        viewmodel.sendggSuccse.observe(this){
            ToastUtils.showLong("发送成功")
            viewmodel.getGg(8,10)
            gonggAdpter.addData(0,it)
            gonggAdpter.notifyDataSetChanged()
        }
    }




}